#!/bin/bash

SCRIPT_PATH=$(dirname $0)
# IOS_CMAKE="${SCRIPT_PATH}/../../MNN/cmake/ios.toolchain.cmake"
IOS_CMAKE="ios.toolchain.cmake"


build_type=Release
if [ "x$DEBUG" != "x" ]; then
    build_type=Debug
fi
echo "build_type:" ${build_type}

echo -e "begin build faceEngine lib\n========================================="
rm -rf build_ios
mkdir build_ios
cd build_ios

echo "now arm7,arm7s,arm64"
cmake -DCMAKE_TOOLCHAIN_FILE=${IOS_CMAKE} -DCMAKE_BUILD_TYPE=${build_type} -DIOS_PLATFORM=OS -DENABLE_BITCODE=0 .. -G "Xcode"
cmake --build . --config ${build_type}

cd ..

# rm -rf build_ios_simulator
# mkdir build_ios_simulator
# cd build_ios_simulator

# cmake -DCMAKE_TOOLCHAIN_FILE=${IOS_CMAKE} -DCMAKE_BUILD_TYPE=${build_type} -DIOS_PLATFORM=SIMULATOR -DARCHS="x86_64"  .. -G "Xcode"
# cmake --build . --config ${build_type}

# cd ..

echo -e "begin merge lib\n========================================="

rm -rf ../release/release_for_ios/lib/argus.framework
cp -r ./build_ios/${build_type}-iphoneos/augus.framework ../release/release_for_ios/lib/
cp -r ./build_ios/${build_type}-iphoneos/augus.framework.dSYM ../release/release_for_ios/lib/
mkdir -p ../release/release_for_ios/lib/augus.framework/Headers
cp ../include/augus/*.h* ../release/release_for_ios/lib/augus.framework/Headers
# lipo -create ./build_ios/${build_type}-iphoneos/augus.framework/augus ./build_ios_simulator/${build_type}-iphonesimulator/augus.framework/augus -output ../release/release_for_ios/lib/augus.framework/augus
lipo -create ./build_ios/${build_type}-iphoneos/augus.framework/augus -output ../release/release_for_ios/lib/augus.framework/augus

lipo -info ../release/release_for_ios/lib/augus.framework/augus
